import { defHttp } from '/@/utils/http/axios'
import { getMenuListResultModel, MenuItem, PageMenuParam } from './model/menuModel'
import { Fuzzy, PageResult } from '../model/baseModel'

enum Api {
  PageMenu = '/sysMenu/page',
  GetMenuList = '/sysMenu/userMenu',
  AddMenu = '/sysMenu/add',
  Fuzzy = '/sysMenu/fuzzy',
  Delete = '/sysMenu/delete',
  TreeAll = '/sysMenu/treeAll',
  ListByRole = '/sysMenu/listByRole',
}

export const getMenuList = () => {
  return defHttp.get<getMenuListResultModel>({ url: Api.GetMenuList }, { urlPrefix: '/user' })
}

export const pageMenu = (param: PageMenuParam) => {
  return defHttp.get<PageResult<MenuItem>>(
    { url: Api.PageMenu, params: param },
    { urlPrefix: '/user' },
  )
}

export const addMenu = (param) => {
  return defHttp.post<null>({ url: Api.AddMenu, params: param }, { urlPrefix: '/user' })
}

export const fuzzy = (keyword: string) => {
  return defHttp.get<Fuzzy[]>({ url: Api.Fuzzy, params: { keyword } }, { urlPrefix: '/user' })
}

export const del = (id: string) => {
  return defHttp.post<null>(
    { url: Api.Delete, params: { id } },
    { urlPrefix: '/user', errorMessageMode: 'modal', successMessage: 'message' },
  )
}

export const treeAll = () => {
  return defHttp.get<any>({ url: Api.TreeAll }, { urlPrefix: '/user' })
}

export const listByRole = (roleId: string) => {
  return defHttp.get<any>({ url: Api.ListByRole, params: { roleId } }, { urlPrefix: '/user' })
}
